{extend name="admin@publics/base"/}
{block name="script_after"}
<script>
Ext.define('admin.index.CURDViewController', {
	extend: 'Ext.app.ViewController',
	alias: 'controller._AdminIndexController',
	_admin_index_index_Menu_Itemclick: function(view, record, item, index, e){
		var _Item = record.data;
		if(_Item['type'] == 0 || _Item['url'] == ''){
			return false;
		}
		_Item['name'] = _Item['name'].replace(/\//g, ".")
		var _Data = {
			'id':'Mt_'+_Item['id'],
			'title':_Item['text'],
			'iconCls':_Item['iconCls'],
			'name':_Item['name'],
		};
		var _Tabs = Ext.getCmp(_Data.id);
		var MainTans = Ext.getCmp('MainTans');
		if(_Item['name']){
			if(!_Tabs){
				var _Tabs = Ext.create("Ext.ux.IFrame", {
					id:_Data.id,
					iconCls:_Data.icon,
					title:_Data.title,
					closable: true,
					closeAction:'destroy',
					frameName: _Item['name'].replace(/\//g, "_"),
                	src: _Item['url'],
				});
				MainTans.add(_Tabs);
			}
			_Tabs.show();
		}
	},
});
Ext.define('admin.index.CURDViewModel', {
    extend: 'Ext.app.ViewModel',
    alias: 'viewmodel._AdminIndexModel',
	data: {
		// 软件
		soft	: _SOFT,
		// 软件
		web		: _WEB,
		// 用户
		user	: _USER,
	},

});

Ext.define('admin.index.index.menu', {
	extend: 'Ext.tab.Panel',
	alias: 'widget.admin_index_index_menu',
	style: 'background:#1b60a5',
	activeTab: 0,
	plain: true,
	tabPosition: 'left',
	cls:'_main_menu',
	menu: _WEB['menu'],
	defaults:{
		xtype: 'panel',
		bodyBorder: true,
		scrollable: true,
		defaults:{
			xtype: 'treepanel',
			viewConfig: {
				rootVisible: false
			}
		},
	},
	initComponent: function () {
		var _Menu = this.menu;
		var _Menu_Arr =[];
		for(var i=0;i<_Menu.length;i++){
			var _Store = Ext.create('Ext.data.TreeStore', {
				root: {
					expanded: true,
					children: _Menu[i]['children']
				}
			});
			var _Item =  Ext.create('Ext.tree.Panel',{
				title: _Menu[i]['text'],
				iconCls: _Menu[i]['iconCls'],
				store: _Store,
				rootVisible: false,
				bodyBorder:false,
				listeners:{
					itemclick:'_admin_index_index_Menu_Itemclick'
				}
			});
			_Menu_Arr.push(_Item);
		}
		this.items = _Menu_Arr;
        this.callParent(arguments);
    }
})
Ext.define('admin.index.index', {
    extend: 'Ext.container.Viewport',
    alias: 'widget.admin_index_index',
    requires: [
        'admin.index.CURDViewModel',
        'admin.index.CURDViewController',
        'Ext.ux.TabCloseMenu',
        'Ext.ux.TabReorderer',
		'admin.index.index.menu',
    ],
    controller: '_AdminIndexController',
    viewModel: {
        type: '_AdminIndexModel'
    },
    layout: 'border',
    items: [
        {
            xtype: 'panel',
            region: 'center',
            layout: 'fit',
			bodyPadding:5,
			bodyStyle:'background:#ddd',
            dockedItems: [
                {
                    xtype: 'toolbar',
                    dock: 'top',
                    height: 50,
                    items: [
                        {
                            xtype: 'image',
                            height: 40,
                            style: 'background:#efefef;border:1px solid #ddd',
                            width: 40,
							bind: {
								src: '{user.avatar}'
							}
                        },
                        {
                            xtype: 'label',
							bind: {
								html: '{user.truename} [{user.username}]<br/>{user.role}'
							},
                        },
						'->',
						/*{if condition="_CheckAuth('admin/Index/ruserinfo')"}*/
						{text: "资料",iconCls:'tf tf-userinfo',handler: function () {
							var _Data = {
								'id':'Mt_admin_user_ruserinfo',
								'title':'修改资料',
								'name':'admin/index/ruserinfo',
								'url':'{:url("admin/Index/ruserinfo")}',
							};
							var _Tabs = Ext.getCmp(_Data.id);
							var MainTans = Ext.getCmp('MainTans');
							if(_Tabs){
								_Tabs.destroy()
							}
							var _Tabs = Ext.create("Ext.ux.IFrame", {
								id:_Data.id,
								title:_Data.title,
								closable: true,
								closeAction:'destroy',
								frameName: _Data['name'].replace(/\//g, "_"),
								src: _Data['url'],
							});
							MainTans.add(_Tabs);
							_Tabs.show();
						}},
						/*{/if}*/
						/*{if condition="_CheckAuth('admin/Index/rpassword')"}*/
						{text: "密码",iconCls:'tf tf-reset_password',handler: function () {
							var _Data = {
								'id':'Mt_admin_user_ruserinfo',
								'title':'修改密码',
								'name':'admin/index/rpassword',
								'url':'{:url("admin/Index/rpassword")}',
							};
							var _Tabs = Ext.getCmp(_Data.id);
							var MainTans = Ext.getCmp('MainTans');
							if(_Tabs){
								_Tabs.destroy()
							}
							var _Tabs = Ext.create("Ext.ux.IFrame", {
								id:_Data.id,
								title:_Data.title,
								closable: true,
								closeAction:'destroy',
								frameName: _Data['name'].replace(/\//g, "_"),
								src: _Data['url'],
							});
							MainTans.add(_Tabs);
							_Tabs.show();
						}},
						/*{/if}*/
						{
							iconCls: 'tf tf-logout',handler: function(){
								window.location.href=_PATH['site']+'/admin/publics/logout';
							}
						}
                    ]
                }
            ],
            items: [
                {
					id:'MainTans',
                    xtype: 'tabpanel',
                    activeTab: 0,
                    items: [
						Ext.create("Ext.ux.IFrame", {
							id:'Mt_console',
							iconCls:'tf tf-os',
							title:'控制台',
							scrollable: true,
							src:_PATH['site']+'/admin/index/console'
						})
                    ],
                    plugins: [
                        {
                            ptype: 'tabclosemenu'
                        },
                        {
                            ptype: 'tabreorderer'
                        }
                    ]
                }
            ]
        },
        {
            xtype: 'panel',
            region: 'west',
            width: 250,
            layout: 'fit',
            dockedItems: [
                {
                    xtype: 'toolbar',
                    dock: 'top',
                    height: 50,
                    style: 'background:#1b60a5',
                    items: [
                        {
                            xtype: 'image',
                            height: 40,
							bind: {
								src: '{web.logo}'
							}
                        }
                    ]
                }
            ],
            items: {xtype:'admin_index_index_menu'}
        },
        {
            xtype: 'panel',
            region: 'south',
            dockedItems: [
                {
                    xtype: 'toolbar',
                    dock: 'top',
                    height: 50,
                    style: 'background:#1b60a5',
					items:[
						{xtype:'label',html:' Copyright © {:config("soft.copyright")} {:config("soft.name")}<sup>{:config("soft.version")}</sup>',style:'color:#ccc'},
						'->',
						{text:'联系管理员',handler: function(){
							window.open("http://wpa.qq.com/msgrd?v=3&uin={:config('admin_qq')}&site=qq&menu=yes")
						}},
						{text:'官网',handler: function(){
							window.open("{:config('soft.site')}")
						}},
						{text:'论坛',handler: function(){
							window.open("{:config('soft.bbs')}")
						}},
						{text:'手册',handler: function(){
							window.open("{:config('soft.doc')}")
						}},
						{text:'技术支持',handler: function(){
							window.open("http://wpa.qq.com/msgrd?v=3&uin={:config('soft.qq')}&site=qq&menu=yes")
						}},
					]
                }
            ]
        }
    ]
});

Ext.application({
	name: 'admin',
	appFolder:_PATH['site']+'/admin',
	extend: 'Ext.app.Application',
	autoCreateViewport: 'admin.index.index'
});
</script>
{/block}